home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Games / Xconq 7.0d16 / Xconq 7.0d16 src / mac / mac.h next >
Encoding:
Text File  |  1993-11-20  |  10.5 KB  |  407 lines  |  [TEXT/KAHL]

  1. /* Copyright (c) 1992, 1993  Stanley T. Shebs. */
  2. /* This program may be used, copied, modified, and redistributed freely */
  3. /* for noncommercial purposes, so long as this notice remains intact. */
  4.  
  5. /* Definitions for the Mac interface. */
  6.  
  7. #undef USE_CMDLINE
  8. #undef USE_CONSOLE
  9.  
  10. #ifdef THINK_C
  11. #include <MacHeaders>
  12. #endif /* THINK_C */
  13.  
  14. #ifndef THINK_C /* assume MPW */
  15. #include <Values.h>
  16. #include <Types.h>
  17. #include <Resources.h>
  18. #include <QuickDraw.h>
  19. #include <Fonts.h>
  20. #include <Events.h>
  21. #include <Windows.h>
  22. #include <Menus.h>
  23. #include <TextEdit.h>
  24. #include <Dialogs.h>
  25. #include <Desk.h>
  26. #include <ToolUtils.h>
  27. #include <Memory.h>
  28. #include <SegLoad.h>
  29. #include <Files.h>
  30. #include <Folders.h>
  31. #include <OSUtils.h>
  32. #include <OSEvents.h>
  33. #include <DiskInit.h>
  34. #include <Packages.h>
  35. #include <Traps.h>
  36. #include <Lists.h>
  37. #include <PPCToolbox.h>
  38. #include <AppleEvents.h>
  39. #include <StandardFile.h>
  40. #include <Sound.h>
  41. #endif
  42.  
  43. #ifndef THINK_C
  44. #define QD(whatever) (qd.##whatever)
  45. #else
  46. #define QD(whatever) (whatever)
  47. #endif
  48.  
  49. #define top_left(rect) (*(Point *) &(rect.top))
  50. #define bottom_right(rect) (*(Point *) &(rect.bottom))
  51.  
  52. #include "macdefs.h"
  53. #include "macimf.h"
  54.  
  55. /* How many magnifications we're supporting. */
  56.  
  57. #define NUMPOWERS 8
  58.  
  59. enum grays {
  60.     blackgray,
  61.     darkgray,
  62.     mediumgray,
  63.     lightgray,
  64.     whitegray,
  65.     fullcolor
  66. };
  67.  
  68. /* The types of available designer tools. */
  69.  
  70. enum tooltype {
  71.     notool,
  72.     terraintool,
  73.     unittool,
  74.     peopletool,
  75.     featuretool,
  76.     brushsizetool,
  77.  
  78.     materialtool,
  79.     elevationtool,
  80.     temperaturetool,
  81.     cloudstool,
  82.     windstool
  83. };
  84.  
  85. /* The user interface substructure.  This is only allocated for sides with
  86.    attached displays. */
  87.  
  88. typedef struct a_ui {
  89.     short followaction;       /* move to where a change has occured */
  90.     int itertime;
  91.     int active;
  92. } UI;
  93.  
  94. /* Each side can open up any number and shape of maps. */
  95.  
  96. #define MAXSELECTIONS 500
  97.  
  98. typedef struct a_map {
  99.     short sx, sy;
  100.     long  totsw, totsh;
  101.     short pxw, pxh;            /* size of window in pixels */
  102.     short vx, vy;            /* lower left of viewport in hex coords */
  103.     short vw, vh;            /* Boundaries of viewport in hex coords */
  104.     short power;            /* index to this map's magnification */
  105.     short mag;                /* magnification of each hex (a power of 2) */
  106.     short vcx, vcy;            /* center of the view */
  107.     short hw, hh;            /* pixel dims of a hex cell */
  108.     short hch;                /* height of hex cell between centers */
  109.     short uw, uh;            /* pixel dims of unit subcell */
  110.     short toph;
  111.     WindowPtr window;
  112.     ControlHandle hscrollbar;
  113.     ControlHandle vscrollbar;
  114.     /* How to draw the map. */
  115.     short drawterrain;        /* Display solid color terrain on the map? */
  116.     short drawgrid;            /* Draw outlines around hexes? */
  117.     short drawhexpats;        /* Draw terrain patterns? */
  118.     short drawothermaps;    /* Draw outlines of other maps? */
  119.     short drawunits;        /* Draw units on the map? */
  120.     short drawnames;        /* Draw unit names/numbers on the map? */
  121.     short oldesttoshow;        /* the relative time of the oldest data */
  122.     short agetofade;        /* point at which to gray out the display */
  123.     short newesttoshow;        /* the relative time of the newest data */
  124.     short fadeterrain;        /* fade world features as well as units? */
  125.     short lowestaltitude;   /* the lowest altitude of units to display */
  126.     short highestaltitude;    /* the highest altitude of units to display */
  127.     short drawborders;
  128.     short drawconnections;
  129.     short drawpeople;        /* Draw people sides on the map? */
  130.     short drawelevations;    /* Draw elevations on the map? */
  131.     short drawmaterials[MAXMTYPES];
  132.     short nummaterialstodraw;
  133.     short drawlighting;        /* Draw day/night on the map? */
  134.     short drawtemperature;    /* Draw temperatures on the map? */
  135.     short drawwinds;
  136.     short drawclouds;
  137.     short drawstorms;
  138.     short drawplans;
  139.     short drawai;
  140.     short autoselect;
  141.     Unit *curunit;
  142.     short moveonclick;
  143.     int numselections;
  144.     int maxselections;
  145.     Unit **selections;
  146.     Rect contentrect;
  147.     RgnHandle cellrgn;
  148.     int cellrgnx, cellrgny;
  149.     int maxdepth;           /* Largest # of bits/pixel of screens this map uses */
  150.     struct a_map *next;        /* Link to the next map. */
  151. } Map;
  152.  
  153. /* Each side can open up any number of lists of units. */
  154.  
  155. #define MAXINLIST 500
  156.  
  157. typedef struct a_list {
  158. #if (MAXSIDES < 32)
  159.     long sides;                      /* mask of sides to display the units of */
  160. #else
  161.     short sides[MAXSIDES];
  162. #endif
  163.     int mainsortmi;
  164.     int listglimpsed;              /* list glimpsed units also? */
  165.     enum sortkeys sortkeys[MAXSORTKEYS];  /* attributes to sort list elements on */
  166.     UnitVector *contents;
  167.     int numunits;
  168.     int firstvisible;
  169.     int lastvisible;
  170.     int firstvisfield;
  171.     int lastvisfield;
  172.     int largeicons;
  173.     int shouldreorg;
  174.     WindowPtr window;
  175.     ControlHandle hscrollbar;
  176.     ControlHandle vscrollbar;
  177.     struct a_list *next;
  178. } List;
  179.  
  180. /* A closer look at a unit. */
  181.  
  182. typedef struct a_unit_closeup {
  183.     struct a_unit *unit;
  184.     WindowPtr window;
  185.     struct a_unit_closeup *next;
  186. } UnitCloseup;
  187.  
  188. /* A closer look at a side. */
  189.  
  190. typedef struct a_side_closeup {
  191.     struct a_side *side;
  192.     DialogPtr dialog;
  193.     struct a_side_closeup *next;
  194. } SideCloseup;
  195.  
  196. /* Iteration over all of a side's maps. */
  197.  
  198. #define for_all_maps(m)  \
  199.   for ((m) = maplist; (m) != NULL; (m) = (m)->next)
  200.  
  201. /* Iteration over all of a side's lists. */
  202.  
  203. #define for_all_lists(l)  \
  204.   for ((l) = listlist; (l) != NULL; (l) = (l)->next)
  205.  
  206. /* Iteration over all of a side's side closeups. */
  207.  
  208. #define for_all_side_closeups(c)  \
  209.   for ((c) = sidecloseuplist; (c) != NULL; (c) = (c)->next)
  210.  
  211. #define for_all_unit_closeups(c)  \
  212.   for ((c) = unitcloseuplist; (c) != NULL; (c) = (c)->next)
  213.  
  214. /* Other useful macros. */
  215.  
  216. #define window_width(w) ((w)->portRect.right - (w)->portRect.left)
  217. #define window_height(w) ((w)->portRect.bottom - (w)->portRect.top)
  218.  
  219. #define clip_to_limits(lo,x,hi) (max((lo), min((x), (hi))))
  220.  
  221. #define hexagon_adjust(m) (area.xwrap ? 0 : ((area.height / 2) * (m)->hw) / 2)
  222.  
  223. #define partial_views() (!(g_see_all() || dside->designer || weseeall))
  224.  
  225. #define all_terrain_visible()  \
  226.   (seeall || terrainseen || dside->designer || weseeall)
  227.  
  228. #define terrain_visible(xw, y)  \
  229.   (seeallterrain || terrain_view(dside, xw, y) != UNSEEN)
  230.  
  231. #define units_visible(x, y)  \
  232.   (seeall || dside->designer || weseeall || cover(dside, wrap(x), y) >= 1)
  233.  
  234. #define borders_visible(x, y, d)  \
  235.   (seeall || dside->designer || weseeall || seen_border(dside, x, y, d))
  236.  
  237. #define bords_to_draw(m) (numbordtypes > 0 && bwid[(m)->power] > 0)
  238.  
  239. #define conns_to_draw(m) (numconntypes > 0 && cwid[(m)->power] > 0)
  240.  
  241. #define draw_any_materials(m) (0)
  242.  
  243. #define any_borders_at(x, y, b) (aux_terrain_at(x, y, b) != 0)
  244.  
  245. #define any_connections_at(x, y, c) (aux_terrain_at(x, y, c) != 0)
  246.  
  247. enum {
  248.     dontdraw,
  249.     useblocks,
  250.     usepictures,
  251.     usepolygons
  252. };
  253.  
  254. #define p2c(pstr,cbuf)  \
  255.   strncpy(cbuf, ((char *) (pstr) + 1), pstr[0]);  cbuf[pstr[0]] = '\0';
  256.  
  257. extern Side *dside;
  258.  
  259. extern int mags[], hws[], hhs[], hcs[], uws[], uhs[];
  260. extern int dolin[];
  261. extern int bsx[NUMPOWERS][7], bsy[NUMPOWERS][7], lsx[NUMPOWERS][6], lsy[NUMPOWERS][6];
  262.  
  263. Map *map_from_window();
  264. List *list_from_window();
  265. SideCloseup *side_closeup_from_window();
  266.  
  267. #define pascalify(STR) \
  268.   sprintf(tmpbuf, " %s", STR);  \
  269.   tmpbuf[0] = strlen(STR);
  270.  
  271. extern int playsounds;
  272.  
  273. extern int nummaps;
  274.  
  275. extern ImageFamily *uimages;
  276. extern ImageFamily *timages;
  277. extern ImageFamily *eimages;
  278.  
  279. extern ImageColor **tcolors;
  280.  
  281. extern WindowPtr helpwin;
  282. extern struct a_helpnode *curhelpnode;
  283. extern char *helpstring;
  284. extern int helpscreentop;
  285. extern TEHandle helptext;
  286.  
  287. extern WindowPtr instructionswin;
  288.  
  289. extern WindowPtr gamewin;
  290. extern ControlHandle gamevscrollbar;
  291.  
  292. extern WindowPtr constructionwin;
  293. extern ListHandle constructionunitlist;
  294. extern ListHandle constructiontypelist;
  295.  
  296. extern WindowPtr designwin;
  297. extern enum tooltype tooltype;
  298. extern short curutype;
  299. extern short curttype;
  300. extern short cursidenumber;
  301. extern short curfid;
  302. extern Feature *curfeature;
  303.  
  304. extern WindowPtr historywin;
  305.  
  306. extern MenuHandle sidemenu;
  307. extern MenuHandle utypemenu;
  308. extern MenuHandle mtypemenu;
  309. extern MenuHandle ttypemenu;
  310.  
  311. extern int hasColorQD;
  312.  
  313. extern int minscreendepth;
  314. extern int maxscreendepth;
  315.  
  316. extern int sbarwid;
  317.  
  318. extern int bwid[];
  319. extern int bwid2[];
  320. extern int cwid[];
  321.  
  322. extern WindowPtr *winmenuwins;
  323.  
  324. extern int defaultdrawgrid;           /* Display grid on the map? */
  325. extern int defaultdrawnames;           /* Display unit names/numbers on the map? */
  326.  
  327. extern int modaltool;
  328.  
  329. extern int defaultmoveonclick;
  330. extern int defaultautoselect;
  331.  
  332. extern PolyHandle polygons[];
  333. extern int lastpolyx[], lastpolyy[];
  334. extern PolyHandle gridpolygons[];
  335. extern int lastgridpolyx[], lastgridpolyy[];
  336.  
  337. extern RgnHandle cellrgns[];
  338. extern int lastcellrgnx[], lastcellrgny[];
  339. extern RgnHandle gridcellrgns[];
  340. extern int lastgridcellrgnx[], lastgridcellrgny[];
  341.  
  342. extern struct a_map *maplist;       /* chain of maps that we're using */
  343. extern struct a_list *listlist;     /* chain of lists */
  344. extern struct a_unit_closeup *unitcloseuplist;     /* chain of unit closeups */
  345. extern struct a_side_closeup *sidecloseuplist;     /* chain of side closeups */
  346.  
  347. extern CursHandle paintcursors[];
  348.  
  349. extern CursHandle cellpaintor;
  350. extern CursHandle bordpaintor;
  351. extern CursHandle connpaintor;
  352. extern CursHandle unitpaintor;
  353. extern CursHandle peoplepaintor;
  354. extern CursHandle featurepaintor;
  355. extern CursHandle materialpaintor;
  356. extern CursHandle elevpaintor;
  357. extern CursHandle cloudpaintor;
  358. extern CursHandle temppaintor;
  359.  
  360. extern CursHandle movecursors[];
  361. extern CursHandle nomovecursor;
  362. extern CursHandle allmovecursor;
  363. extern CursHandle grayarrowcursor;
  364. extern CursHandle opencrosscursor;
  365.  
  366. extern char *curdatestr;
  367.  
  368. extern int mayseeall;
  369.  
  370. extern int weseeall;
  371.  
  372. extern RGBColor graycolor, blackcolor;
  373.  
  374. extern enum grays gridgray;
  375. extern enum grays unseengray;
  376. extern enum grays bggray;
  377.  
  378. extern RGBColor gridcolor;
  379. extern RGBColor unseencolor;
  380. extern RGBColor bgcolor;
  381. extern RGBColor blackcolor;
  382.  
  383. extern int conwid, tophgt;
  384.  
  385. /* Function prototypes. */
  386.  
  387. char *savefile_name();
  388. char *newsfile_name();
  389.  
  390. char *get_string_from_item(Handle itemhandle);
  391.  
  392. Map *create_map(int power);
  393.  
  394. UnitCloseup *unit_closeup_from_window();
  395. UnitCloseup *find_unit_closeup(Unit *unit);
  396.  
  397. void draw_unit_image(WindowPtr win, int sx, int sy, int sw, int sh, int u, int e, int mod);
  398. void draw_side_emblem(WindowPtr win, int ex, int ey, int ew, int eh, int e);
  399.  
  400. void xform(Map *map, int x, int y, int *sxp, int *syp);
  401. void xform_unit(Map *map, Unit *unit, int *sxp, int *syp, int *swp, int *shp);
  402. void xform_unit_self(Map *map, Unit *unit, int *sxp, int *syp, int *swp, int *shp);
  403. void xform_occupant(Map *map, Unit *transport, Unit *unit, int sx, int sy, int sw, int sh, int *sxp, int *syp, int *swp, int *shp);
  404. int nearest_cell(Map *map, int sx, int sy, int *xp, int *yp);
  405. int nearest_boundary(Map *map, int sx, int sy, int *xp, int *yp, int *dirp);
  406. int nearest_unit(Map *map, int sx, int sy, Unit **unitp);
  407.